package com.bocloud.cmp.driver.convertor.os;

import java.util.List;

import org.openstack4j.model.storage.block.Volume;

import com.bocloud.cmp.driver.convertor.BeanConvert;
import com.bocloud.cmp.model.VolumeModel;
import com.google.common.collect.Lists;

public class ConvertVolumes implements BeanConvert<VolumeModel, Volume> {

    @Override
    public List<VolumeModel> convertList(List<? extends Volume> volumes) {
        List<VolumeModel> models = Lists.newArrayList();
        for (Volume volume : volumes) {
            models.add(convertModel(volume));
        }
        return models;
    }

    @Override
    public VolumeModel convertModel(Volume volume) {
        VolumeModel model = new VolumeModel();
        model.setCategory(volume.getVolumeType());
        model.setGmtCreate(volume.getCreated());
        model.setImageId(volume.getImageRef());
        if (null == volume.getName() || volume.getName().isEmpty()) {
            model.setName(volume.getId());
        } else {
            model.setName(volume.getName());
        }
        model.setRemark(volume.getDescription());
        model.setSize(volume.getSize());
        model.setStatus(volume.getStatus().name());
        model.setType(volume.getVolumeType());
        model.setVolumeId(volume.getId());
        model.setUuid(volume.getSourceVolid());
        model.setZone(volume.getZone());
        return model;
    }
}
